package view;


import javax.swing.*;
import java.awt.*;

/**
 * Created by Pavel Nikolaev
 */
public class HtmlViewportLayout extends ViewportLayout {
    // Single instance used by HtmlViewport.
    static HtmlViewportLayout HTML_SHARED_INSTANCE = new HtmlViewportLayout();

    @Override
    public void layoutContainer(Container parent) {
        JViewport vp = (JViewport)parent;
        Component view = vp.getView();

        Dimension vpSize = vp.getSize();
        Dimension extentSize = vp.toViewCoordinates(vpSize);
        view.setSize(vp.getSize());
        Dimension correctedViewSize = view.getSize();
        view.setPreferredSize(correctedViewSize);

        Point viewPosition = vp.getViewPosition();
        vp.setViewPosition(viewPosition);

        if (correctedViewSize.getHeight() != vp.getHeight())
            vp.setViewSize(correctedViewSize);
    }
}
